package com.example.iotest.bio;

import java.io.*;

public class StreamTest {
    public static void main(String[] args) throws IOException {
        byte[] byteArray = new byte[]{12,23,34,34,56};
        ByteArrayInputStream byteArrayInputStream=new ByteArrayInputStream(byteArray);
        int b;
        /*while ((b=byteArrayInputStream.read())!=-1){
            System.out.println(b);
        }*/
        byte[] buf=new byte[1024];
        ByteArrayOutputStream byteArrayOutputStream=new ByteArrayOutputStream(10);

        while ((b=byteArrayInputStream.read())!=-1){
            byteArrayOutputStream.write(b);
        }

//        System.out.println(System.console());
        String fileName = "D:\\Resources\\GitProjects\\io-test\\io-test\\io-test\\src\\main\\resources\\files\\1.txt";
        File file = new File(fileName);
        FileInputStream fileInputStream=new FileInputStream(file);
        BufferedInputStream bufferedInputStream=new BufferedInputStream(fileInputStream);
        int read2 = bufferedInputStream.read();
        int read1 = fileInputStream.read(buf);
        System.out.println("file.length() "+file.length());
        System.out.println("fileInputStream read: "+read1);
        ByteArrayInputStream byteArrayInputStream1=new ByteArrayInputStream(buf);
        int available = byteArrayInputStream1.available();
        int read = byteArrayInputStream1.read(buf);
        byteArrayInputStream1.reset();
        System.out.println("byteArrayInputStream read: "+read);
        System.out.println(available);
        System.out.println("bufferedInputStream.read(): "+(char)read2+(char)bufferedInputStream.read());


        PrintStream printStream=new PrintStream("D:\\Resources\\GitProjects\\io-test\\io-test\\io-test\\src\\main\\resources\\files\\1.txt");
        printStream.println("111111111111111111111111111111你好");
        PrintWriter printWriter=new PrintWriter("D:\\Resources\\GitProjects\\io-test\\io-test\\io-test\\src\\main\\resources\\files\\1.txt");
        printWriter.println("111111111");
        printWriter.close();
        printWriter.println("1111111112");
        FileOutputStream fileOutputStream=new FileOutputStream("D:\\Resources\\GitProjects\\io-test\\io-test\\io-test\\src\\main\\resources\\files\\1.txt");
        fileOutputStream.write("你好".getBytes());
        fileOutputStream.close();
        fileOutputStream.close();
//        fileOutputStream.write("aa".getBytes());
    }
}
